﻿using System;
using NUnit.Framework;
using Rhino.Mocks;

using ServiceManager;
using ServiceFacade;

namespace Test_ServiceManager
{
    [TestFixture]
    public class Test_ServiceTask
    {
        private Service service;
        private ServiceTask serviceTask;
        private MockRepository mockRepository;
        private IServiceFacade mockServiceFacade;

        [SetUp]
        public void Setup()
        {
            this.service = new Service("Test_Service", ServiceStatus.Stopped);
            this.serviceTask = new ServiceTask(service, CommandType.StartService);
            this.mockRepository = new MockRepository();
            this.mockServiceFacade = (IServiceFacade)this.mockRepository.DynamicMock(typeof(IServiceFacade));
        }

        [Test]
        public void Test_ServiceTask_Constructor()
        {
            Assert.IsNotNull(this.serviceTask.Service);
            Assert.AreEqual(CommandType.StartService, this.serviceTask.CommandType);
            Assert.AreEqual(TaskType.Unscheduled, this.serviceTask.TaskType);
            Assert.AreEqual(TaskStatus.Pending, this.serviceTask.TaskStatus);
        }

        [Test]
        public void Test_ServiceTask_Execute_CompletedStatus()
        {
            using (this.mockRepository.Ordered())
            {
                this.mockServiceFacade.startService("Test_Service");
            }
            this.mockRepository.ReplayAll();
            serviceTask.Execute(mockServiceFacade);
            this.mockRepository.VerifyAll();

            Assert.AreEqual(TaskStatus.Completed, serviceTask.TaskStatus);
        }

    }
}
